// Table C.3: Effects of road toll on ICEV ownership with household fixed effects


*===============================================================================
* Step 1: Run regressions (1) and (2)
*===============================================================================

use    "${dataout}MainDataset" , clear

***********************************
***** Choose years to keep!  ******
keep if year>=2015 & year<=2017
***********************************

keep if couple==1 

/**********************************************/
/*******  Two adult households ****************/
/*******    Both working   ********************/
/******* Two treatment variables **************/
/*******  Years 2015-2017       ***************/
/**********************************************/

** Select variables to loop over: 
local outcomelist 	ICE_fam_count   
local treatvar1list toll_fam_mean         
local treatvar2list ptl_fam_km_mean     

** Regressions - loop over: outcome, treatment, year
foreach outcome in `outcomelist'{
foreach treatvar1 in `treatvar1list'{
foreach treatvar2 in `treatvar2list'{

reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality   , ///
absorb($FE   $household  $income  $employment  $education  i.year  i.familienr_num ) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean)  
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean) 
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean) 

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0   
estadd scalar MeanDepCon = r(mean), replace 
local MeanDepCon = r(mean)  

local Proportional1 = _b[`treatvar1']/`MeanDepCon'  
estadd scalar Proportional1 =  `Proportional1'
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1')  
estadd scalar Elasticity1 =  `Elasticity1'

local Proportional2 = _b[`treatvar2']/`MeanDepCon' 
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2') 
estadd scalar Elasticity2 =  `Elasticity2' 

estadd local year="2015-17" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="\checkmark", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg2 
estimates save "${ster}TableC3_reg2" , replace

** Mark main sample
capt drop MainSample
gen MainSample=0
replace MainSample=1 if e(sample)==1

// Same as regression above, but without family FE
reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality    if MainSample==1 , ///
absorb($FE   $household  $income  $employment  $education  i.year  /*i.familienr_num */) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean) 
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean)  
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean) 

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0  
estadd scalar MeanDepCon = r(mean), replace   
local MeanDepCon = r(mean) 

local Proportional1 = _b[`treatvar1']/`MeanDepCon'  
estadd scalar Proportional1 =  `Proportional1' 
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1')  
estadd scalar Elasticity1 =  `Elasticity1'

local Proportional2 = _b[`treatvar2']/`MeanDepCon'  
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2')  
estadd scalar Elasticity2 =  `Elasticity2'

estadd local year="2015-17" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg1 
estimates save "${ster}TableC3_reg1" , replace
}
}
}

*===============================================================================
* STEP 2: Run regressions (3) and (4)
*===============================================================================

use    "${dataout}MainDataset" , clear

***********************************
***** Choose years to keep!  ******
keep if year==2008 | year==2017
***********************************
keep if couple==1

/**********************************************/
/*******  Two adult households ****************/
/*******    Both working   ********************/
/******* Two treatment variables **************/
/*******  Years 2008 AND 2017       ***********/
/**********************************************/

** Select variables to loop over: 
local outcomelist ICE_fam_count               
local treatvar1list toll_fam_mean        
local treatvar2list ptl_fam_km_mean     

** Regressions - loop over: outcome, treatment, year
foreach outcome in `outcomelist'{
foreach treatvar1 in `treatvar1list'{
foreach treatvar2 in `treatvar2list'{

reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality   , ///
absorb($FE   $household  $income  $employment  $education  i.year  i.familienr_num ) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean)  
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean) 
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean)  

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0 
estadd scalar MeanDepCon = r(mean), replace 
local MeanDepCon = r(mean) 

local Proportional1 = _b[`treatvar1']/`MeanDepCon'  
estadd scalar Proportional1 =  `Proportional1' 
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1') 
estadd scalar Elasticity1 =  `Elasticity1' 

local Proportional2 = _b[`treatvar2']/`MeanDepCon'  
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2') 
estadd scalar Elasticity2 =  `Elasticity2'

estadd local year="2008,2017" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="\checkmark", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg4
estimates save "${ster}TableC3_reg4" , replace

** Mark main sample
capt drop MainSample
gen MainSample=0
replace MainSample=1 if e(sample)==1

reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality  if  MainSample==1 , ///
absorb($FE   $household  $income  $employment  $education  i.year  /*i.familienr_num*/ ) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean) 
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean)  
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean)  

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0  
estadd scalar MeanDepCon = r(mean), replace   
local MeanDepCon = r(mean)  

local Proportional1 = _b[`treatvar1']/`MeanDepCon'  
estadd scalar Proportional1 =  `Proportional1' 
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1')  
estadd scalar Elasticity1 =  `Elasticity1' 

local Proportional2 = _b[`treatvar2']/`MeanDepCon'   
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2')   
estadd scalar Elasticity2 =  `Elasticity2' 

estadd local year="2008,2017" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg3 
estimates save "${ster}TableC3_reg3" , replace
}
}
}

*===============================================================================
* STEP 3: Run regressions (5) and (6)
*===============================================================================

use    "${dataout}MainDataset" , clear

***********************************
***** Choose years to keep!  ******
keep if year==2008 | year==2017
***********************************
keep if couple==1

/**********************************************/
/*******  Two adult households ****************/
/*******    Both working   ********************/
/******* Two treatment variables **************/
/*******  Years 2008 AND 2017       ***********/
/******* Same residence as in 2008 ************/
/**********************************************/

preserve
	keep if year==2008
	keep  familienr indid1 indid2 grkrets_num 
	rename grkrets_num grkrets_num_2008
	sort familienr indid1 indid2
	tempfile helpfile
	save `helpfile'
restore
// Restrict to HH that live in the same neighborhood as in 2008
sort familienr indid1 indid2
merge m:1 familienr indid1 indid2 using `helpfile'  , keep (master match)
tab _merge 
drop _merge

gen SameNeigh = 0
replace SameNeigh=1 if grkrets_num==grkrets_num_2008
keep if SameNeigh==1

** Select variables to loop over: 
local outcomelist ICE_fam_count                 
local treatvar1list toll_fam_mean
local treatvar2list ptl_fam_km_mean     

foreach outcome in `outcomelist'{
foreach treatvar1 in `treatvar1list'{
foreach treatvar2 in `treatvar2list'{

reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality   , ///
absorb($FE   $household  $income  $employment  $education  i.year  i.familienr_num ) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean)
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean) 
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean) 

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0   
estadd scalar MeanDepCon = r(mean), replace   
local MeanDepCon = r(mean)  

local Proportional1 = _b[`treatvar1']/`MeanDepCon'   
estadd scalar Proportional1 =  `Proportional1'
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1')   
estadd scalar Elasticity1 =  `Elasticity1' 

local Proportional2 = _b[`treatvar2']/`MeanDepCon'   
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2') 
estadd scalar Elasticity2 =  `Elasticity2'

estadd local year="2008,2017" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="\checkmark", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg6
estimates save "${ster}TableC3_reg6" , replace

** Mark main sample
capt drop MainSample
gen MainSample=0
replace MainSample=1 if e(sample)==1

reghdfe `outcome' `treatvar1'  `treatvar2'  $age    $distance  $time  $publictime  $publicquality  if  MainSample==1 , ///
absorb($FE   $household  $income  $employment  $education  i.year   ) vce(cluster $clustervar) 

summarize `outcome' if e(sample)==1
estadd scalar MeanDep = r(mean), replace
local MeanDep = r(mean)  
summarize `treatvar1' if e(sample)==1
estadd scalar Treat1 = r(mean), replace
local Treat1 = r(mean) 
summarize `treatvar2' if e(sample)==1
estadd scalar Treat2 = r(mean), replace
local Treat2 = r(mean) 

summarize `outcome' if e(sample)==1 & `treatvar1'==0 & `treatvar2'==0  
estadd scalar MeanDepCon = r(mean), replace  
local MeanDepCon = r(mean)  

local Proportional1 = _b[`treatvar1']/`MeanDepCon'   
estadd scalar Proportional1 =  `Proportional1' 
local Elasticity1 = (_b[`treatvar1']/`MeanDep') / (1/`Treat1')  
estadd scalar Elasticity1 =  `Elasticity1' 

local Proportional2 = _b[`treatvar2']/`MeanDepCon'   
estadd scalar Proportional2 =  `Proportional2' 
local Elasticity2 = (_b[`treatvar2']/`MeanDep') / (1/`Treat2')  
estadd scalar Elasticity2 =  `Elasticity2' 

estadd local year="2008,2017" , replace
estadd local grkFE="\checkmark", replace
estadd local grkbFE="\checkmark", replace
estadd local HHcon="\checkmark", replace
estadd local HHWork="\checkmark", replace
estadd local HHFE="", replace
estadd local PublicTime="\checkmark", replace
eststo TableC3_reg5 
estimates save "${ster}TableC3_reg5" , replace
}
}
}

/* =============================================================================
   STEP 4: Load .ster files, make and export table
 =============================================================================*/
   
eststo drop *

* === Loading ster files =======================================================
estimates use "${ster}TableC3_reg1" 
estadd local year="2015-2017" , replace
eststo

estimates use "${ster}TableC3_reg2"
estadd local Sample="All" , replace   
estadd local year="2015-2017" , replace
eststo

estimates use "${ster}TableC3_reg3"
estadd local year="2008,2017" , replace
eststo

estimates use "${ster}TableC3_reg4"
estadd local year="2008,2017" , replace
eststo

estimates use "${ster}TableC3_reg5"
estadd local year="2008,2017" , replace
eststo

estimates use "${ster}TableC3_reg6"
estadd local year="2008,2017" , replace
eststo

* === Making table =============================================================

// Latex 
esttab est*  ///
using  "${tables}TableC3.tex" ///
, keep(toll_fam_mean) ///
title("Outcome: ICE_fam_count") ///
booktabs nonotes  /*nomtitle  label*/  coeflabels(toll_fam_mean "Road toll (NOK)") ///
mgroups("2015--2017" "2008 and 2017" , pattern(1 0  1 0 0 0) prefix(\multicolumn{@span}{c}{)   suffix(}) span erepeat (\cmidrule(lr){@span})) ///
mtitles("All" "All" "All" "All" "\shortstack{Same \\residence}" "\shortstack{Same \\residence}") ///
stats( N year grkFE grkbFE HHFE  HHWork HHcon  PublicTime MeanDep Treat1 Treat2 Proportional1 Elasticity1, label("N" "Year"  "Neighborhood residence FE" "Neighborhood work FE"  "Household FE"  "Ind-work controls" "HH and ind controls" "Public transit (minutes)" "Mean outcome" "Mean road toll (NOK)" "Mean bus lane (km)"  "Road toll, prop. effect" "Road toll elasticity" ) fmt(%9.0fc a3) ) ///
b(5) se(5) star(* 0.10 ** 0.05 *** 0.01)    replace

// Latex - without table opening
esttab est*  ///
using  "${tables}TableC3_fragment.tex" ///
, keep(toll_fam_mean) ///
title("Outcome: ICE_fam_count") ///
booktabs nonotes  /*nomtitle  label*/  coeflabels(toll_fam_mean "Road toll (NOK)") ///
mgroups("2015--2017" "2008 and 2017" , pattern(1 0  1 0 0 0) prefix(\multicolumn{@span}{c}{)   suffix(}) span erepeat (\cmidrule(lr){@span})) ///
mtitles("All" "All" "All" "All" "\shortstack{Same \\residence}" "\shortstack{Same \\residence}") ///
stats( N year grkFE grkbFE HHFE  HHWork HHcon  PublicTime MeanDep Treat1 Treat2 Proportional1 Elasticity1, label("N" "Year"  "Neighborhood residence FE" "Neighborhood work FE"  "Household FE"  "Ind-work controls" "HH and ind controls" "Public transit (minutes)" "Mean outcome" "Mean road toll (NOK)" "Mean bus lane (km)"  "Road toll, prop. effect" "Road toll elasticity" ) fmt(%9.0fc a3) ) ///
b(5) se(5) star(* 0.10 ** 0.05 *** 0.01)  fragment replace

// Print to screen
esttab est*  ///
, keep(toll_fam_mean) ///
title("Outcome: ICE_fam_count") ///
booktabs nonotes  /*nomtitle  label*/  coeflabels(toll_fam_mean "Road toll (NOK)") ///
mgroups("2015--2017" "2008 and 2017" , pattern(1 0  1 0 0 0) prefix(\multicolumn{@span}{c}{)   suffix(}) span erepeat (\cmidrule(lr){@span})) ///
mtitles("All" "All" "All" "All" "\shortstack{Same \\residence}" "\shortstack{Same \\residence}") ///
stats( N year grkFE grkbFE HHFE  HHWork HHcon  PublicTime MeanDep Treat1 Treat2 Proportional1 Elasticity1, label("N" "Year"  "Neighborhood residence FE" "Neighborhood work FE"  "Household FE"  "Ind-work controls" "HH and ind controls" "Public transit (minutes)" "Mean outcome" "Mean road toll (NOK)" "Mean bus lane (km)"  "Road toll, prop. effect" "Road toll elasticity" ) fmt(%9.0fc a3) ) ///
b(5) se(5) star(* 0.10 ** 0.05 *** 0.01) 



 
 
 
 